/*
 * Copyright (c) 2010-2011 Plugger Antonio Begue Ponce. All Rights Reserved.
 *
 * This file is part of Plugger Framework.
 *
 *  Plugger Framework is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU Lesser General Public License version 3 as published by
 *  the Free Software Foundation.
 *
 *  Plugger Framework is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public License
 *  along with Plugger Framework.  If not, see <http://www.gnu.org/licenses/>.
 */

package org.plugger.infrastructure.rules;

/**
 * An abstract basic entity rule.
 *
 * @author Antonio Begue
 * @version $Revision: 1.0 $
 */
public abstract class RuleBase implements IRule {
    private String ruleId;
    private IBrokenRuleMessages errorMessages;

    public RuleBase() {
    }

    public abstract boolean isValid();

    /**
     * @return the ruleId
     */
    public String getRuleId() {
        return ruleId;
    }

    /**
     * @param ruleId the ruleId to set
     */
    public void setRuleId(String ruleId) {
        this.ruleId = ruleId;
    }

    /**
     * @return the errorMessages
     */
    public IBrokenRuleMessages getErrorMessages() {
        return errorMessages;
    }

    /**
     * @param errorMessages the errorMessages to set
     */
    public void setErrorMessages(IBrokenRuleMessages errorMessages) {
        this.errorMessages = errorMessages;
    }

    public String getErrorMessage() {
        return formatMessage(errorMessages.getRuleDescription(ruleId));
    }

    public abstract String formatMessage(String message);
}
